package com.szpx.service.impl;

import com.szpx.entity.User;
import com.szpx.mapper.UserMapper;
import com.szpx.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;


@Service
@Transactional //事务处理策略
public class UserServiceImpl implements UserService {
	
	@Autowired
	private UserMapper userMapper;
	
	@Override
	public User selectUserById(Integer id) {
		//  public function from mybatis
		return userMapper.selectByPrimaryKey(id);
	}
	
	@Override
	public List<User> selectAllUser() {
		return userMapper.selectAll();
	}
	
	@Override
	public int addUser(User user) {
		return userMapper.insertSelective(user);
	}
	
	@Override
	public int delUser(Integer id) {
		return userMapper.deleteByPrimaryKey(id);
	}
	
	@Override
	public int updateUser(User user) {
		return userMapper.updateByPrimaryKeySelective(user);
	}
	
	@Override
	public User login(User user) {
		return userMapper.selectOne(user);
	}
	
	@Override
	public List<User> getListByCon(User user) {
		return userMapper.getListByCon(user);
	}
}
